/*
 * This program is free software: you can redistribute it and/or modify it under
 * the terms of the GNU General Public License as published by the Free Software
 * Foundation, either version 3 of the License, or (at your option) any later
 * version.
 * 
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
 * details.
 * 
 * You should have received a copy of the GNU General Public License along with
 * this program. If not, see <http://www.gnu.org/licenses/>.
 */
package jmmos.gameserver.model.actor.instance;

import java.util.logging.Logger;

import jmmos.gameserver.ai.MMOCharacterAI;
import jmmos.gameserver.model.MMOCharPosition;
import jmmos.gameserver.model.actor.MMOCharacter;
import jmmos.gameserver.model.actor.knownlist.StaticObjectKnownList;
import jmmos.gameserver.model.actor.stat.StaticObjStat;
import jmmos.gameserver.model.actor.status.StaticObjStatus;
import jmmos.gameserver.model.actor.templates.MMOCharTemplate;
import jmmos.gameserver.model.items.MMOWeapon;
import jmmos.gameserver.model.items.instance.MMOItemInstance;
import jmmos.gameserver.model.skills.MMOSkill;
import jmmos.gameserver.network.serverpackets.ShowTownMap;
import jmmos.gameserver.network.serverpackets.StaticObject;

/**
 * @author godson
 */
public class MMOStaticObjectInstance extends MMOCharacter
{
	protected static final Logger log = Logger.getLogger(MMOStaticObjectInstance.class.getName());
	
	/** The interaction distance of the MMOStaticObjectInstance */
	public static final int INTERACTION_DISTANCE = 150;
	
	private final int _staticObjectId;
	private int _meshIndex = 0; // 0 - static objects, alternate static objects
	private int _type = -1; // 0 - map signs, 1 - throne , 2 - arena signs
	private ShowTownMap _map;
	
	/** This class may be created only by MMOCharacter and only for AI */
	public class AIAccessor extends MMOCharacter.AIAccessor
	{
		protected AIAccessor()
		{
		}
		
		@Override
		public MMOStaticObjectInstance getActor()
		{
			return MMOStaticObjectInstance.this;
		}
		
		@Override
		public void moveTo(int x, int y, int z, int offset)
		{
		}
		
		@Override
		public void moveTo(int x, int y, int z)
		{
		}
		
		@Override
		public void stopMove(MMOCharPosition pos)
		{
		}
		
		@Override
		public void doAttack(MMOCharacter target)
		{
		}
		
		@Override
		public void doCast(MMOSkill skill)
		{
		}
	}
	
	@Override
	public MMOCharacterAI getAI()
	{
		return null;
	}
	
	/**
	 * @return Returns the StaticObjectId.
	 */
	public int getStaticObjectId()
	{
		return _staticObjectId;
	}
	
	/**
	 * @param objectId
	 * @param template
	 * @param staticId
	 */
	public MMOStaticObjectInstance(int objectId, MMOCharTemplate template, int staticId)
	{
		super(objectId, template);
		setInstanceType(InstanceType.MMOStaticObjectInstance);
		_staticObjectId = staticId;
	}
	
	@Override
	public final StaticObjectKnownList getKnownList()
	{
		return (StaticObjectKnownList) super.getKnownList();
	}
	
	@Override
	public void initKnownList()
	{
		setKnownList(new StaticObjectKnownList(this));
	}
	
	@Override
	public final StaticObjStat getStat()
	{
		return (StaticObjStat) super.getStat();
	}
	
	@Override
	public void initCharStat()
	{
		setStat(new StaticObjStat(this));
	}
	
	@Override
	public final StaticObjStatus getStatus()
	{
		return (StaticObjStatus) super.getStatus();
	}
	
	@Override
	public void initCharStatus()
	{
		setStatus(new StaticObjStatus(this));
	}
	
	public int getType()
	{
		return _type;
	}
	
	public void setType(int type)
	{
		_type = type;
	}
	
	public void setMap(String texture, int x, int y)
	{
		_map = new ShowTownMap("town_map." + texture, x, y);
	}
	
	public ShowTownMap getMap()
	{
		return _map;
	}
	
	@Override
	public final int getLevel()
	{
		return 1;
	}
	
	/**
	 * Return null.
	 */
	@Override
	public MMOItemInstance getActiveWeaponInstance()
	{
		return null;
	}
	
	@Override
	public MMOWeapon getActiveWeaponItem()
	{
		return null;
	}
	
	@Override
	public MMOItemInstance getSecondaryWeaponInstance()
	{
		return null;
	}
	
	@Override
	public MMOWeapon getSecondaryWeaponItem()
	{
		return null;
	}
	
	@Override
	public boolean isAutoAttackable(MMOCharacter attacker)
	{
		return false;
	}
	
	/**
	 * Set the meshIndex of the object.<br>
	 * <B><U> Values </U> :</B>
	 * <ul>
	 * <li>default textures : 0</li>
	 * <li>alternate textures : 1</li>
	 * </ul>
	 * @param meshIndex
	 */
	public void setMeshIndex(int meshIndex)
	{
		_meshIndex = meshIndex;
		this.broadcastPacket(new StaticObject(this));
	}
	
	/**
	 * <B><U> Values </U> :</B>
	 * <ul>
	 * <li>default textures : 0</li>
	 * <li>alternate textures : 1</li>
	 * </ul>
	 * @return the meshIndex of the object
	 */
	public int getMeshIndex()
	{
		return _meshIndex;
	}
	
	@Override
	public void updateAbnormalEffect()
	{
	}
	
	@Override
	public void sendInfo(MMOPcInstance activeChar)
	{
		activeChar.sendPacket(new StaticObject(this));
	}
}
